﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

using PureMVC.Patterns;
using PureMVC.Interfaces;

using GEF2.Model.Storage;

namespace GEF2.Model
{
    public class SearchProxy : Proxy, IProxy
    {
        public new const string NAME = "SearchProxy";
        private EntityProxy mEntityProxy;

        public SearchProxy(EntityProxy entityProxy)
            : base(NAME)
        {
            mEntityProxy = entityProxy;
        }

        public List<Entity> searchByPoint(Point point)
        {
            List<Entity> result = new List<Entity>();
            foreach(Entity entity in mEntityProxy.Entitys)
            {
                if (entity.containsPoint(point))
                {
                    result.Add(entity);
                }
            }
            return result;
        }
        public List<Entity> searchByRect(System.Drawing.Rectangle rect)
        {
            List<Entity> result = new List<Entity>();
            foreach(Entity entity in mEntityProxy.Entitys)
            {
                if (entity.containsRect(rect))
                {
                    result.Add(entity);
                }
            }
            return result;
        }

        public List<Entity> searchByName(string name)
        {
            List<Entity> result = new List<Entity>();
            foreach (Entity entity in mEntityProxy.Entitys)
            {
                if (entity.Name == name)
                {
                    result.Add(entity);
                }
            }
            return result;
        }

        public bool isNameUnique(string name)
        {
            var list = searchByName(name);
            return list.Count() == 0;
        }
    }

}
